package com.china08.yxyapi.api.manage.stu.mystudy.mistakes;

import java.text.ParseException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.mistakes.StuMistakesQuesNote;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.mistakes.StuMistakesQuesNoteRepository;
import com.china08.yxyapi.util.DateToolUtils;

/**
 * 错题本--学生端--错题笔记--下方编辑一条查看（单一）
 * 
 * @author LiuWeidong
 *
 */
@CrossOrigin
@RestController
public class StuMistakesQuesNoteEditSchController extends YxyApiBaseController {

    @Autowired
    private StuMistakesQuesNoteRepository stuMistakesQuesNoteRepository;

    @RequestMapping(value = "/api_yw/manage/stu/mystudy/mistakes/note/editsch", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel model)
            throws ParseException {

        StuMistakesQuesNote smqn = stuMistakesQuesNoteRepository.findOne(model.id);
        Assert.notNull(smqn, "该笔记内容不存在！");

        RespModel respModel = new RespModel();
        respModel.id = smqn.getId();
        respModel.note = smqn.getNote();
        String aa = DateToolUtils.format(smqn.getPublishDate(), DateToolUtils.FORMAT_LONG);
        respModel.publishDate = aa;
        return respModel;
    }

    /* 请求参数 */
    protected static class ReqModel extends YxyApiReqModel {

        // 笔记id
        public String id;
    }

    /* 响应参数 */
    protected static class RespModel extends YxyApiRespModel {

        // 笔记id
        public String id;

        // 笔记内容
        public String note;

        // 笔记发布时间
        public String publishDate;
    }
}
